package com.bestcem.xm.user.util.business;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 异步线程池工具类
 *
 * @author wangyunyun <yunyun.wang@idiaoyan.com>
 * @version v1.0
 * @date 2022/4/20 10:47
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class AsyncUtil {

    /**
     * 核心线程数
     */
    private static final int CORE_POOL_SIZE = 2;

    /**
     * 最大线程数
     */
    private static final int MAX_POOL_SIZE = 5;

    /**
     * 线程队列size
     */
    private static final int QUEUE_SIZE = 50;

    /**
     * 空闲线程存活时间
     */
    private static final Long KEEP_ALIVE = 10L;

    /**
     * 处理大量组织更新任务线程池：数量 >1w
     */
    public static final ThreadPoolExecutor MUCH_GROUP_THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(
                    CORE_POOL_SIZE,
                    MAX_POOL_SIZE,
                    KEEP_ALIVE,
                    TimeUnit.SECONDS,
                    new ArrayBlockingQueue<>(QUEUE_SIZE));

    /**
     * 核心线程数
     */
    private static final int LITTLE_CORE_POOL_SIZE = 2;

    /**
     * 最大线程数
     */
    private static final int LITTLE_MAX_POOL_SIZE = 10;

    /**
     * 线程队列size
     */
    private static final int LITTLE_QUEUE_SIZE = 500;

    /**
     * 空闲线程存活时间
     */
    private static final Long LITTLE_KEEP_ALIVE = 10L;

    /**
     * 处理少量组织更新任务线程池：数量 <1w
     */
    public static final ThreadPoolExecutor LITTLE_GROUP_THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(
                    LITTLE_CORE_POOL_SIZE,
                    LITTLE_MAX_POOL_SIZE,
                    LITTLE_KEEP_ALIVE,
                    TimeUnit.SECONDS,
                    new ArrayBlockingQueue<>(LITTLE_QUEUE_SIZE));

    /**
     * 核心线程数
     */
    private static final int EXPORT_CORE_POOL_SIZE = 2;

    /**
     * 最大线程数
     */
    private static final int EXPORT_MAX_POOL_SIZE = 10;

    /**
     * 线程队列size
     */
    private static final int EXPORT_QUEUE_SIZE = 500;

    /**
     * 空闲线程存活时间
     */
    private static final Long EXPORT_KEEP_ALIVE = 10L;

    /**
     * 处理组织导出任务线程池：数量 <1w
     */
    public static final ThreadPoolExecutor EXPORT_GROUP_THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(
            EXPORT_CORE_POOL_SIZE,
            EXPORT_MAX_POOL_SIZE,
            EXPORT_KEEP_ALIVE,
            TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(EXPORT_QUEUE_SIZE));

}
